home *** CD-ROM | disk | FTP | other *** search
- Path: news.uh.edu!cosc19z5
- From: cosc19z5@Bayou.UH.EDU (Spasmo)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character
- Followup-To: comp.lang.c,comp.unix.programmer
- Date: 12 Apr 1996 20:19:43 GMT
- Organization: University of Houston
- Message-ID: <4kmdsv$ojc@masala.cc.uh.edu>
- References: <4kj66f$k0o@ren.cei.net> <4kjh25INNf2e@anvil.ugrad.cs.ubc.ca> <4kko80$8np@news.ld.centuryinter.net> <4kkvvsINN8fs@keats.ugrad.cs.ubc.ca>
- NNTP-Posting-Host: bayou.uh.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Kazimir Kylheku (c2a192@ugrad.cs.ubc.ca) wrote:
- : In article <4kko80$8np@news.ld.centuryinter.net>,
- : Don & Gayle Peterson <dongayle@centuryinter.net> wrote:
- : >It's a shame I didn't see the full original posting, but maybe your
- : >solution is 'bullshit' too.
- : >A long, long time ago, K&R taught me that the beauty in unix is
- : >simplicity: don't re-invent a tool that already exists. If all the
- : >original author wants to do is read 2 (or more) files side by side,
- : >what's wrong with good old pr?
- : >or, getting fancier, and comparing them, sdiff?...depending on the
- : >situation, get nuts, use paste... join...
- : >
- : >Getting raw side-by-side output from text files at the shell is as
- : >simple as:
- : > pr -m file1 file2 ...
- : >or
- : > pr -t -m ....
- : >if you don't want the pr header.
-
- : I sometimes recommend unix commands myself---for example when someone wanted to
- : know how to delete lines from a text stream, I facetiously suggested ``sed''.
-
- : However, this is a C newsgroup, not comp.unix.shell. The C language is used in
- : all kinds of places. It's somewhat arrogant to suggest UNIX solutions to C
- : questions.
-
- Actually from where I'm standing this is the comp.unix.programmer newsgroup.
- Don't you love crossposting? It also means that the response was in fact on
- topic for us, but apparently not for you--the price of crossposting.
-
-
- : >If this requirement is within C code where the multiple inputs
- : >screw up the ability to use pipes, then forgive me for not knowing all
- : >the facts.
- : >But,
- : >The other response using strlen isn't 'wrong'; there are lots of
- : >ways to skin a cat.
-
- : Not if you are being paid by the cat. :) And yes, the strlen() response was
- : damn wrong. It completely ignored the possiblity that fgets() may return a
- : string that doesn't have a newline at the end. Just the sort of useless answer
- : that we don't need on comp.lang.c: incorrect, and is directed at the wrong
- : question anyway.
-
- The strlen() response was right, however it had the possibility of producing
- undesired effects under certain conditions. The user wanted a way to remove
- newlines, and the response above did it. Of course in the case of a overly
- long line, the response would remove a valid character--however the fact
- remains that it does remove the newline, and with the addition of some minor
- code can be made much safer--yet no one has shown the boundary conditions
- because it's obvious that they can exist, and they are easy to accomodate.
-
- Also given the application, the conditions that would make the strlen()
- solution unsafe may not even occur. So, the details of making the solution
- more robust are left out. Perhaps this is an unwarranted assumption, however
- it was an assumption that was made--at least in my case. I was one of the
- folks who suggested the strlen() solution as I use it when needed (with
- proper checks of course). And in case you haven't noticed, the strlen() fix
- is directed at newline stripping which *IS* the right question. Go back
- and re-read the original post.
-
- And yes there are better solutions to the problem. I like the strchr solution
- posted by a few folks and will probably use that in preference to
- strlen(), however it does not take away from the validity of the original
- solution.
-
-
- : > have yet to use a version of Unix that will
- : >blow up on forcing a null into a returned NULL pointer.
-
- : What are you using for a Unix? Are you for real? Boy, you are going to get
- : flamed for this.
-
- Some of us are adults and don't flame others for what may be considered
- improper code. If anything we use tact and inform others of potential
- problems. If you find the need to flame for what you consider to be
- coding mistakes then maybe you should wait until you get out of middle
- school before posting on usenet again.
-
- [Snip]
-
- : >The mere nature of the author's request would indicate that
- : >he is looking at text files, (what sense is there doing side-by-
- : >sides of binaries?) So, why not a utility that works with, and
- : >assumes, text? Unix text files have \n terminators. Correct me
- : >if I'm wrong.
- : >
- : >So, why write a bunch of lines of _elegant_ code to simply
- : >clobber a newline?
-
- : Because it's less typing than the inelegant (and incorrect, unrobust)
- : equivalent?
-
-
- And using UNIX commands to achieve what you need instead of C is far
- more elegant, far less typing, far more robust, and far easier than
- any code you can write. Get a grip the guy above is discussing using
- UNIX utilities instead of re-inventing the wheel. And he's got a very
- valid point. With all the beautiful tools available under UNIX we can
- get a lot done without having to write any code. As it stands people
- jump into a compiler to fix problems that can be better fixed without
- writing software. He has a very valid point. You'd do well to stop
- babbling and start listening.
-
-
- : >I also notice that your solution does not take into account any
- : >output formatting: what happens to the output from f2 when f1 is
- : >shorter that f2? From what I see, it starts looking like output from
- : >f1.
-
- : This was not called for in the informal requirements. In fact, if f1 runs out
- : of lines, f2 is flushed left. The original posting (which I'm aware you didn't
- : see) had not specified any sort of separator character, though adding one is
- : trivial.
-
- The original posting also didn't ask for a different way of accomplishing the
- desired task, merely for newline removal. So the supposedly elegant
- code that was posted was way off mark.
-
-
- [Snip]
-
- : >I'm new to this group, and your type of response is kind of scary:
- : >does everyone here have a chip on their shoulder?
- : >Cut others a little slack!
-
- : Incorrect answers, or answers to the wrong question are not helpful to anyone.
- : What is scary is that the proliferation of poor answers continues once the
- : question has already been beat to death and has been correctly answered by
- : people who actually _test_ their code, however trivial, before posting it to
- : the newsgroup.
- : --
-
-
- Firstly not everyone is as harsh as the you who criticized everyone's solution
- and then took the idiotic step of telling the original poster a solution to an
- entirely different problem from what the poster asked about. The question was
- about removing newlines, not about criticizing the means with which he
- wrote the code. Now there's nothing wrong with showing faults or better ways
- of doing things if it is done with an iota of *TACT*. Rampaging about and
- insulting others and then posting a solution which ends up in a bad case of
- foot in mouth is not in the spirit of usenet.
-
- For the record the vast majority of the folks that I have dealt with on here
- are very helpful, friendly and knowledgable, unlike you. You are not helpful,
- the "solution" you posted was to an entirely different problem from what was
- asked about, you are far from friendly (calling solutions you disagree with
- "bullshit" is considered rude), and judging from the fact that you can't even
- post an on-topic solution you are far from knowledgable. I don't claim to be
- an expert on anything--I know what I know and I acknowledge when I don't know
- something, but I try to help and I am open to advice. I'd suggest you develop
- a sense of humility as well.
-
- Finally there is nothing wrong in using different solutions. Granted some
- solutions are better than others and sometimes for brevity a solution is
- posted without error checking--but that's because it's an illustration of
- how to solve the problem, not a complete solution in itself. Insulting people
- based on solutions you don't approve of just makes you look like a jerk,
- especially when you end up posting garbage like you've done now.
-
- --
-
- .A. G-Force! 1 AM Houston Time
- AAAAA On the Cartoon Network!
- AAY:YAA
- A':::`A This informative message was
- ::::::: brought to you by Spasmo.
- ::( )::
- :::::::
- :::::::
- :::::::
- :::::::
- .A. .do:::::::::::bo. .A.
- AAA .:::::::::::::::::::::. AAA
- d:::::::::::::::::::::::::::::::::::::::::::b
- Y:::::::::::::::::::::::::::::::::::::::::::Y
- `YjY `:::::::|::|::|:::::::' YjY'
- `::|::|::|::'
- |
-